<?php

namespace Mifan\Alist\client;

trait Instances
{

    private static $instances = [];

    /**
     * @param array|mixed $property
     *
     * @return self
     */
    public static function getInstance($property = []): self
    {
        $key = md5(json_encode($property));
        self::$instances[$key] = self::$instances[$key] ?? new self($property);

        return self::$instances[$key];
    }


    /**
     * @param array $property
     */
    public function __construct(array $property = [])
    {
        if ($property) {
            foreach ($property as $name => $value) {
                $this->$name = $value;
            }
        }
    }

}